﻿using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace Sensor_Test
{
    public class Program
    {
        static AnalogIn readingIn = new AnalogIn((AnalogIn.Pin.Ain2));
        public static void Main()
        {
         
            readingIn.SetLinearScale(0, 1023);
            //bool ledState = false;

            //OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

            while (true)
            {
                double rangeFinderRead = ((readingIn.Read()));
                //rangeFinderRead = (9462 / (rangeFinderRead - 16.92));  //At 40 cm --> reading is about 20 cm; At 60 cm --> Reading is about 30
                //WORKING rangeFinderRead = ((69007)*(System.Math.Pow(rangeFinderRead, (-1.357)))); <--Working Equation with 5V plugged in
                //rangeFinderRead = (((0.0001)*(System.Math.Pow(rangeFinderRead, 2))) - (0.1903*rangeFinderRead) + 74.536);
                //rangeFinderRead = (0.5398*rangeFinderRead) + 6.8724;
                Debug.Print(rangeFinderRead.ToString());
                // Sleep for 500 milliseconds
                Thread.Sleep(300);

                // toggle LED state
                //ledState = !ledState;
                //led.Write(ledState);
            }
        }
        }

    }

